package com.meixiang.fragment.momentsContentFragment;

import android.support.design.widget.AppBarLayout;
import android.support.v4.app.Fragment;

import com.meixiang.R;
import com.meixiang.fragment.service.BaseViewPagerFragment;

/**
 * 作者：黑哥 on 2016/5/5 18:08
 */
public class FragmentSwitching extends BaseViewPagerFragment implements AppBarLayout.OnOffsetChangedListener{
    private RecommendFragment mRecommendFragment;
    private AttentionFragment mAttentionFragment;
    private AppBarLayout mAppBarLayout;
    @Override
    protected String[] getTitles() {
        return new String[]{"推荐","关注"};
    }

    @Override
    protected Fragment[] getFragments() {
        mRecommendFragment=new RecommendFragment();
        mAttentionFragment=new AttentionFragment();
        mAppBarLayout=startAppbar();
        return new Fragment[]{mRecommendFragment,mAttentionFragment};
    }
    @Override
    protected int ColorStyle() {
        return R.color.magenta;
    }

    /**
     * 当完全tab显示 才能使用下拉刷新
     * @param appBarLayout
     * @param verticalOffset
     */
    @Override
    public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
        if (verticalOffset==0){
            mRecommendFragment.setRefreshEnabled(true);
            mAttentionFragment.setRefreshEnabled(true);
        }else{
            mRecommendFragment.setRefreshEnabled(false);
            mAttentionFragment.setRefreshEnabled(false);
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        mAppBarLayout.addOnOffsetChangedListener(this);
    }

    @Override
    public void onPause() {
        super.onPause();
        mAppBarLayout.removeOnOffsetChangedListener(this);
    }
}
